package com.dingding.web.order.action;

import java.util.List;

import javax.annotation.Resource;

import com.dingding.common.core.util.ToolUtil;
import com.dingding.facde.activity.service.ICommonActivityFacade;
import com.dingding.facde.share.IShareActivityFacade;
import com.dingding.order.dto.myorder.SpeCusOrdInfoResult;
import com.dingding.order.service.special.ISpecialCarOrderFacade;
import com.dingding.web.base.action.BaseAction;

/**
 * @Description:订单的控制器
 * @author fengshuonan
 * @date 2016年9月8日 下午3:48:58
 * @version 叮叮搭车
 * @since 2.4
 * @deprecated
 */
@SuppressWarnings("serial")
public class OrderAction extends BaseAction{
	
	@Resource(name = "specialCarOrderFacade")
	private ISpecialCarOrderFacade specialCarOrderFacade;
	
	@Resource(name = "shareActivityFacade")
	private IShareActivityFacade shareActivityFacade;
	
	//活动相关接口
	@Resource(name = "commonActivityFacade")
	private ICommonActivityFacade commonActivityFacade;
	
	/**
	 * @Description:获取乘客的专车订单
	 * @author fengshuonan
	 * @return String
	 * @since 2.4
	 */
	public String getCustomerSpecialOrders(){                       
		
		String telephone = super.getPara("telephone");
		String messageCode = super.getPara("messageCode");
		
		if(ToolUtil.isBlank(telephone) || ToolUtil.isBlank(messageCode)){
			super.writeResponseJsonp(400, "请求数据为空");
			return NONE;
		}
		
		//判断验证码是否正确
		boolean codeFlag = this.shareActivityFacade.isCodeRight(telephone, messageCode);
		if(!codeFlag){
			super.writeResponseJsonp(401, "手机号或验证码错误");
			return NONE;
		}
		
		//获取该用户的所有订单
		List<SpeCusOrdInfoResult> orders = this.specialCarOrderFacade.getSpecialCustomerOrderInfoByPhone(telephone);
		if(orders == null || orders.size() == 0){
			super.writeResponseJsonp(300, "暂无订单");
		}else{
			super.writeResponseJsonp(orders);
		}
		
		return NONE;
	}
	
	
	/**
	 * @Description:取消专车订单
	 * @author fengshuonan
	 * @since 2.4
	 */
	public String cancelOrder(){
		
		String orderId = super.getPara("orderId");
		
		if(ToolUtil.isBlank(orderId)){
			super.writeResponseJsonp(400, "请求数据为空");
			return NONE;
		}
		
		boolean flag = this.specialCarOrderFacade.cancelSpecialOrder(orderId);
		
		if(flag == true){
			super.writeResponseJsonp(200, "取消订单成功");
		}else{
			super.writeResponseJsonp(500, "服务器异常");
		}
		
		return NONE;
	}
	
	/**
	 * @Description:获取电话手机号验证码
	 * @author fengshuonan
	 * @return String
	 * @since 2.4
	 */
	public String getTelePhoneCode(){
		
		String telephone = super.getPara("telephone");
		
		if(ToolUtil.isBlank(telephone)){
			super.writeResponseJsonp(400,"所传数据为空");
			return NONE;
		}
		
		boolean flag = this.shareActivityFacade.sendPhoneMsg(telephone);
		
		if(flag){
			super.writeResponseJsonp(200,"发送成功");
		}else{
			super.writeResponseJsonp(500,"服务器异常");
		}
		return NONE;
	}
}
